#include <iostream>
#include <vector>
#include "cassert"
#include <map>
#include <cmath>
using namespace std;


std::map<double, std::string> number_to_chord = {
	pair<double, std::string>(1,   "C"),
	pair<double, std::string>(1.5, "C#"),
	pair<double, std::string>(2,   "D"),
	pair<double, std::string>(2.5, "D#"),
	pair<double, std::string>(3,   "E"),
	pair<double, std::string>(4,   "F"),
	pair<double, std::string>(4.5, "F#"),
	pair<double, std::string>(5,   "G"),
	pair<double, std::string>(5.5, "G#"),
	pair<double, std::string>(6,   "A"),
	pair<double, std::string>(6.5, "A#"),
	pair<double, std::string>(7,   "B")
};

std::map<std::string, double> chord_to_number = {
	pair<std::string, double>("C"  ,1    ),
	pair<std::string, double>("C#" ,1.5  ),
	pair<std::string, double>("D"  ,2    ),
	pair<std::string, double>("D#" ,2.5  ),
	pair<std::string, double>("E"  ,3    ),
	pair<std::string, double>("F"  ,4    ),
	pair<std::string, double>("F#" ,4.5  ),
	pair<std::string, double>("G"  ,5    ),
	pair<std::string, double>("G#" ,5.5  ),
	pair<std::string, double>("A"  ,6    ),
	pair<std::string, double>("A#" ,6.5  ),
	pair<std::string, double>("B"  ,7    )
};


const std::vector<double> chords{1, 1.5, 2, 2.5, 3, 4, 4.5, 5, 5.5, 6, 6.5, 7};


int get_chord_idx(double chord){
	for (int i = 0; i < chords.size(); ++i)
	{
		if(chords[i] == chord){
			return i;
		}
	}
	return -1;
}


std::string change(std::string origin, int step){
    std::string char_chord(1, origin[0]);
	int idx = get_chord_idx(chord_to_number[char_chord]);
	assert(idx != -1);
	int tmp = (idx + step) < 0 ?  chords.size() - abs(idx + step): (idx + step);
	int result = static_cast<int>(tmp % chords.size());
    auto out = std::string(number_to_chord[chords[result]]);
    if(origin.size() == 2){
        out += "m";
    }
	return out;
}


int main(int argc, const char **args){
	std::vector<std::string> c = {"Em", "D"};
	cout << "size:" << chords.size() << "\n";
	int step = -2;
    for (auto s : c) {
        cout << s << " ";
    }
    cout << endl;
    for (int i = 0; i < c.size(); ++i) {
        cout << change(c[i], step) << " ";
    }
	return 0;
}